package com.xx.controller;

import com.xx.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpSession;

@Controller
public class MyController {

    @RequestMapping("/hello")
    public String Hello() {
        System.out.println("Hello Interceptor");
        return "success";
    }

    @RequestMapping(value = "/login", method = RequestMethod.POST)
    public String Login(User user, HttpSession httpSession) {
        System.out.println(user);
        if ("xx".equals(user.getUsername()) && "xx".equals(user.getPwd())) {
            httpSession.setAttribute("USER_SESSION", user);
            return "success";
        }
        return "redirect:/index.jsp";
    }

    @RequestMapping(value = "/logout")
    public String Logout(HttpSession httpSession) {
        // 清空session
        httpSession.invalidate();
        return "redirect:/index.jsp";
    }

    @RequestMapping(value = "/main")
    public String Main(HttpSession httpSession) {
        return "success";
    }
}
